home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / shells / tcshsrc.zoo / tcsh / sh.char.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-25  |  4.6 KB  |  103 lines

  1. /* $Header: /home/hyperion/mu/christos/src/sys/tcsh-6.00/RCS/sh.char.h,v 3.0 1991/07/04 21:49:28 christos Exp $ */
  2. /*
  3.  * sh.char.h: Table for spotting special characters quickly
  4.  *           Makes for very obscure but efficient coding.
  5.  */
  6. /*-
  7.  * Copyright (c) 1980, 1991 The Regents of the University of California.
  8.  * All rights reserved.
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  * 1. Redistributions of source code must retain the above copyright
  14.  *    notice, this list of conditions and the following disclaimer.
  15.  * 2. Redistributions in binary form must reproduce the above copyright
  16.  *    notice, this list of conditions and the following disclaimer in the
  17.  *    documentation and/or other materials provided with the distribution.
  18.  * 3. All advertising materials mentioning features or use of this software
  19.  *    must display the following acknowledgement:
  20.  *    This product includes software developed by the University of
  21.  *    California, Berkeley and its contributors.
  22.  * 4. Neither the name of the University nor the names of its contributors
  23.  *    may be used to endorse or promote products derived from this software
  24.  *    without specific prior written permission.
  25.  *
  26.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  27.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  30.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  32.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  34.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  35.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  36.  * SUCH DAMAGE.
  37.  */
  38. #ifndef _h_sh_char
  39. #define _h_sh_char
  40. #include <ctype.h>
  41.  
  42. extern unsigned short _cmap[];
  43.  
  44. #ifndef NLS
  45. extern unsigned char _cmap_lower[], _cmap_upper[];
  46.  
  47. #endif
  48.  
  49. #define    _Q    0x0001        /* '" */
  50. #define    _Q1    0x0002        /* ` */
  51. #define    _SP    0x0004        /* space and tab */
  52. #define    _NL    0x0008        /* \n */
  53. #define    _META    0x0010        /* lex meta characters, sp #'`";&<>()|\t\n */
  54. #define    _GLOB    0x0020        /* glob characters, *?{[` */
  55. #define    _ESC    0x0040        /* \ */
  56. #define    _DOL    0x0080        /* $ */
  57. #define    _DIG      0x0100        /* 0-9 */
  58. #define    _LET      0x0200        /* a-z, A-Z, _ */
  59. #define    _UP       0x0400        /* A-Z */
  60. #define    _LOW      0x0800        /* a-z */
  61. #define    _XD     0x1000        /* 0-9, a-f, A-F */
  62. #define    _CMD    0x2000        /* lex end of command chars, ;&(|` */
  63. #define _CTR    0x4000        /* control */
  64.  
  65. #define cmap(c, bits)    \
  66.     (((c) & QUOTE) ? 0 : (_cmap[(unsigned char)(c)] & (bits)))
  67.  
  68. #define isglob(c)    cmap(c, _GLOB)
  69. #define isspc(c)    cmap(c, _SP)
  70. #define ismeta(c)    cmap(c, _META)
  71. #define iscmdmeta(c)    cmap(c, _CMD)
  72. #define letter(c)    (((c) & QUOTE) ? 0 : \
  73.              (isalpha((unsigned char) (c)) || (c) == '_'))
  74. #define alnum(c)    (((c) & QUOTE) ? 0 : \
  75.                  (isalnum((unsigned char) (c)) || (c) == '_'))
  76. #ifdef NLS
  77. # define Isspace(c)    (((c) & QUOTE) ? 0 : isspace((unsigned char) (c)))
  78. # define Isdigit(c)    (((c) & QUOTE) ? 0 : isdigit((unsigned char) (c)))
  79. # define Isalpha(c)    (((c) & QUOTE) ? 0 : isalpha((unsigned char) (c)))
  80. # define Islower(c)    (((c) & QUOTE) ? 0 : islower((unsigned char) (c)))
  81. # define Isupper(c)    (((c) & QUOTE) ? 0 : isupper((unsigned char) (c)))
  82. # define Tolower(c)     (((c) & QUOTE) ? 0 : tolower((unsigned char) (c)))
  83. # define Toupper(c)     (((c) & QUOTE) ? 0 : toupper((unsigned char) (c)))
  84. # define Isxdigit(c)    (((c) & QUOTE) ? 0 : isxdigit((unsigned char) (c)))
  85. # define Isalnum(c)    (((c) & QUOTE) ? 0 : isalnum((unsigned char) (c)))
  86. # define Iscntrl(c)     (((c) & QUOTE) ? 0 : iscntrl((unsigned char) (c)))
  87. # define Isprint(c)     (((c) & QUOTE) ? 0 : isprint((unsigned char) (c)))
  88. #else
  89. # define Isspace(c)    cmap(c, _SP|_NL)
  90. # define Isdigit(c)    cmap(c, _DIG)
  91. # define Isalpha(c)    (cmap(c,_LET) && !(((c) & META) && AsciiOnly))
  92. # define Islower(c)    (cmap(c,_LOW) && !(((c) & META) && AsciiOnly))
  93. # define Isupper(c)    (cmap(c, _UP) && !(((c) & META) && AsciiOnly))
  94. # define Tolower(c)    (_cmap_lower[(unsigned char)(c)])
  95. # define Toupper(c)    (_cmap_upper[(unsigned char)(c)])
  96. # define Isxdigit(c)    cmap(c, _XD)
  97. # define Isalnum(c)    (cmap(c, _DIG|_LET) && !(((c) & META) && AsciiOnly))
  98. # define Iscntrl(c)    (cmap(c,_CTR) && !(((c) & META) && AsciiOnly))
  99. # define Isprint(c)    (!cmap(c,_CTR) && !(((c) & META) && AsciiOnly))
  100. #endif
  101.  
  102. #endif /* _h_sh_char */
  103.